@echo off
chcp 65001 >nul
echo ================================
echo   AI-CRM 部署启动脚本
echo ================================
echo.

REM 检查 Docker 是否安装
docker --version >nul 2>&1
if errorlevel 1 (
    echo 错误: 未检测到 Docker，请先安装 Docker
    pause
    exit /b 1
)

REM 创建必要的目录
echo 正在创建数据目录...
if not exist "data\shared-mysql" mkdir data\shared-mysql
if not exist "data\cordys-redis" mkdir data\cordys-redis
if not exist "data\cordys-crm\files" mkdir data\cordys-crm\files
if not exist "data\sqlbot-postgres" mkdir data\sqlbot-postgres
if not exist "data\sqlbot" mkdir data\sqlbot
if not exist "data\dataease" mkdir data\dataease
if not exist "data\one-api" mkdir data\one-api
if not exist "logs\cordys-crm" mkdir logs\cordys-crm
if not exist "logs\dataease" mkdir logs\dataease
if not exist "logs\nginx" mkdir logs\nginx
if not exist "config\shared-mysql" mkdir config\shared-mysql
if not exist "config\nginx\conf.d" mkdir config\nginx\conf.d
if not exist "config\nginx\html" mkdir config\nginx\html
if not exist "config\nginx\ssl" mkdir config\nginx\ssl
if not exist "config\cordys-redis" mkdir config\cordys-redis
if not exist "config\cordys-crm" mkdir config\cordys-crm
if not exist "config\dataease" mkdir config\dataease

echo 目录创建完成
echo.

REM 启动服务
echo 正在启动服务...
docker compose up -d
if errorlevel 1 (
    docker-compose up -d
)

if not errorlevel 1 (
    echo.
    echo ================================
    echo   服务启动成功！
    echo ================================
    echo.
    echo 🌐 统一访问入口（推荐）：
    echo ----------------------------
    echo 导航页面: http://localhost
    echo.
    echo 通过 Nginx 访问：
    echo   Cordys CRM:  http://localhost/crm
    echo   SQLBot:      http://localhost/sqlbot
    echo   DataEase:    http://localhost/dataease
    echo   One API:     http://localhost/one-api
    echo.
    echo 📱 直接访问（原始端口）：
    echo ----------------------------
    echo 1. Cordys CRM
    echo    前端: http://localhost:8081
    echo    后端: http://localhost:8082
    echo    默认账号: admin
    echo    默认密码: CordysCRM
    echo.
    echo 2. SQLBot
    echo    访问: http://localhost:8000
    echo    默认账号: admin
    echo    默认密码: SQLBot@123456
    echo.
    echo 3. DataEase
    echo    访问: http://localhost:8083
    echo    默认账号: admin
    echo    默认密码: dataease
    echo.
    echo 4. One API
    echo    访问: http://localhost:8084
    echo    默认账号: root
    echo    默认密码: 123456
    echo.
    echo 🗄️ 数据库端口：
    echo ----------------------------
    echo 共享 MySQL (Cordys + DataEase): localhost:3306
    echo SQLBot PostgreSQL: localhost:5432
    echo Cordys Redis: localhost:6379
    echo.
    echo 查看日志命令：
    echo docker compose logs -f [服务名]
    echo.
    echo 停止服务命令：
    echo docker compose down
    echo ================================
) else (
    echo.
    echo 错误: 服务启动失败，请检查日志
    pause
    exit /b 1
)

pause

